package com.aaa.service.impl;

import com.aaa.entity.Melody;
import com.aaa.mapper.PreferMapper;
import com.aaa.service.PreferService;
import com.aaa.util.DefaultMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
@Service
public class PreferServiceImpl implements PreferService {

    @Resource
    private PreferMapper preferMapper;

    @Override
    public List<Melody> listAllMelody(String pramykey,String lid) {
        return preferMapper.listAllMelody(pramykey,lid);
    }

    @Override
    public List<Melody> PreferLoad(Integer mid) {
        List<Melody> melodies = preferMapper.PreferLoadAll();//当前用户喜欢的歌单所有歌曲
        Melody melody = preferMapper.PreferLoad(mid);//当前用户选中的歌曲
        List<Melody> melodyList = new ArrayList<>();
        melodyList.add(melody);
        for(int a=0;a<melodies.size();a++){
            melodyList.add(melodies.get(a));
        }

        return melodyList;
    }

    @Override
    public DefaultMsg clickOn(String mid, String lid) {
        int i = preferMapper.clickOn(mid, lid);
        DefaultMsg defaultMsg = new DefaultMsg();
        if(i!=1){
            defaultMsg.setSuccess(0);
            defaultMsg.setMsg("异常");
        }
        return defaultMsg;
    }

    @Override
    public Melody clickMV(String mid) {
        return preferMapper.clickMV(mid);
    }
}
